#include "md5.h"

#include <stdio.h>

static struct md5_ctx ctx;

void print_u32(u32 x) {
    printf("%2.2x%2.2x%2.2x%2.2x",
        ((x >> 0) & 0xff),
        ((x >> 8) & 0xff),
        ((x >> 16) & 0xff),
        ((x >> 24) & 0xff)
    );
}

int main(int argc, char *argv[]) {
    FILE *fp = stdin;
    if (argc > 1) {
        fp = fopen(argv[1], "r");
        if (!fp)
            return -1;
    }

    md5_stream(fp, &ctx);

    print_u32(ctx.A);
    print_u32(ctx.B);
    print_u32(ctx.C);
    print_u32(ctx.D);
    puts("");

    return 0;
}